package com.matrix.framework.web;

import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

/**
 * 静态资源控制器
 * 处理前端SPA应用的路由
 *
 * Copyright © 海平面工作室 版权所有
 *
 * @Author: Leo
 * @Create: 2025/9/20 11:00
 * @Since 1.2
 */
@Controller
public class StaticResourceController {

    /**
     * 处理根路径请求，重定向到前端入口页面
     */
    @GetMapping("/")
    public Mono<Void> index(ServerWebExchange exchange) {
        ServerHttpResponse response = exchange.getResponse();
        response.setStatusCode(HttpStatus.FOUND);
        response.getHeaders().setLocation(URI.create("/index.html"));
        return response.setComplete();
    }

}